package com.fairytask.ui.equipUnit
{
	import com.fairytask.data.ObjectData;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Input;
	import com.fairytask.ui.base.BaseUI;
	
	public class PropertyPart extends BaseUI
	{
		public var HPLabel		:Clip;	//HP
		public var HPInput		:Input;
		public var STLabel		:Clip;	//体力
		public var STInput 	:Input;
		public var strLabel	:Clip;	//力量
		public var strInput 	:Input;
		public var phyLabel	:Clip;	//物攻
		public var phyInput 	:Input;
		public var ingLabel	:Clip;	//智力
		public var ingInput 	:Input;
		public var magLabel	:Clip;	//法攻
		public var magInput 	:Input;
		public var spiLabel	:Clip;	//耐力
		public var spiInput 	:Input;
		public var phyDefLabel	:Clip;	//物防
		public var phyDefInput :Input;
		public var dexLabel	:Clip;	//敏捷
		public var dexInput 	:Input;
		public var magDefLabel	:Clip;	//法防
		public var magDefInput :Input;
		
		//========数据============
		private const ADDPROPCOLOR	:String = "00ff00";	//附加属性颜色
		
		private var _data		:ObjectData;	//显示对象
		private var _bindArr	:Array	=[];	//绑定数据的数组，用于解绑
		
		public function PropertyPart()
		{
			super();
		}
		
		public function bindProp(data:*):void
		{
			if(_data == data)
			{
				return;
			}
			if(null != _data)
			{
				clearAll();
			}
			_data = data;
			_bindArr.push([_data,"Str",bindManager.BindProp(_data, "Str",this,"rStr")]);		//力量
			_bindArr.push([_data,"StrAdd",bindManager.BindProp(_data, "StrAdd",this,"rStr")]);//力量修正
			_bindArr.push([_data,"Ing",bindManager.BindProp(_data, "Ing",this,"rIng")]);		//智力
			_bindArr.push([_data,"IngAdd",bindManager.BindProp(_data, "IngAdd",this,"rIng")]);//智力修正
			_bindArr.push([_data,"Dex",bindManager.BindProp(_data, "Dex",this,"rDex")]);		//敏捷
			_bindArr.push([_data,"DexAdd",bindManager.BindProp(_data, "DexAdd",this,"rDex")]);//敏捷修正
			_bindArr.push([_data,"Spi",bindManager.BindProp(_data, "Spi",this,"rSpi")]);		//敏捷
			_bindArr.push([_data,"SpiAdd",bindManager.BindProp(_data, "SpiAdd",this,"rSpi")]);//敏捷修正
			_bindArr.push([_data,"Sta",bindManager.BindProp(_data, "Sta",this,"rSta")]);		//体质
			_bindArr.push([_data,"StaAdd",bindManager.BindProp(_data, "StaAdd",this,"rSta")]);//体质修正
			
			_bindArr.push([_data,"PhyDamage",bindManager.BindProp(_data, "PhyDamage",this,"rPhyDamage")]);//物理攻击
			_bindArr.push([_data,"PhyDamageAdd",bindManager.BindProp(_data, "PhyDamageAdd",this,"rPhyDamage")]);		//物理攻击
			_bindArr.push([_data,"PhyDamageMul",bindManager.BindProp(_data, "PhyDamageMul",this,"rPhyDamage")]);//物理攻击
			
			_bindArr.push([_data,"MagDamage",bindManager.BindProp(_data, "MagDamage",this,"rMagDamage")]);//法力攻击
			_bindArr.push([_data,"MagDamageAdd",bindManager.BindProp(_data, "MagDamageAdd",this,"rMagDamage")]);		//法力攻击
			_bindArr.push([_data,"MagDamageMul",bindManager.BindProp(_data, "MagDamageMul",this,"rMagDamage")]);//法力攻击
			
			_bindArr.push([_data,"PhyDef",bindManager.BindProp(_data, "PhyDef",this,"rPhyDef")]);		//物妨
			_bindArr.push([_data,"PhyDefAdd",bindManager.BindProp(_data, "PhyDefAdd",this,"rPhyDef")]);//物妨
			_bindArr.push([_data,"PhyDefMul",bindManager.BindProp(_data, "PhyDefMul",this,"rPhyDef")]);//物妨
			
			_bindArr.push([_data,"MagDef",bindManager.BindProp(_data, "MagDef",this,"rMagDef")]);		//法防
			_bindArr.push([_data,"MagDefAdd",bindManager.BindProp(_data, "MagDefAdd",this,"rMagDef")]);//法防
			_bindArr.push([_data,"MagDefMul",bindManager.BindProp(_data, "MagDefMul",this,"rMagDef")]);//法防
			
			_bindArr.push([_data,"HP",bindManager.BindProp(_data, "HP",this,"rHp")]);		//气血
			_bindArr.push([_data,"MaxHP",bindManager.BindProp(_data, "MaxHP",this,"rHp")]);//气血
			_bindArr.push([_data,"MaxHPAdd",bindManager.BindProp(_data, "MaxHPAdd",this,"rHp")]);//最大气血
			
		}
		
		//====================数据处理=========================
		//力量
		public function set rStr(val:String):void
		{
			var propVal	:int = _data.GetPropertiesEx("Str");
			var propAdd	:int = _data.GetPropertiesEx("StrAdd");//附加值
			setVal(strInput,propVal,propAdd);
		}
		
		//智力
		public function set rIng(val:String):void
		{
			var propVal	:int = _data.GetPropertiesEx("Ing");
			var propAdd	:int = _data.GetPropertiesEx("IngAdd");//附加值
			setVal(ingInput,propVal,propAdd);
		}
		
		//耐力
		public function set rSpi(val:String):void
		{
			var propVal	:int = _data.GetPropertiesEx("Spi");
			var propAdd	:int = _data.GetPropertiesEx("SpiAdd");//附加值
			setVal(spiInput,propVal,propAdd);
		}
		
		//敏捷
		public function set rDex(val:String):void
		{
			var propVal	:int = _data.GetPropertiesEx("Dex");
			var propAdd	:int = _data.GetPropertiesEx("DexAdd");//附加值
			setVal(dexInput,propVal,propAdd);
		}
		
		/**
		 * 体质
		 * @param val
		 * 
		 */		
		public function set rSta(val:int):void
		{
			var propVal	:int = _data.GetPropertiesEx("Sta");
			var propAdd	:int = _data.GetPropertiesEx("StaAdd");//附加值
			setVal(STInput,propVal,propAdd);
		}
		
		/**
		 *物理攻击 
		 * @param val
		 * 
		 */		
		public function set rPhyDamage(val:String):void
		{
			//phyInput.htmlStr = ProfileTools.retrieveDamage(_data,ProfileTools.PHYSICAL);
		}
		
		/**
		 *法术攻击 
		 * @param val
		 * 
		 */		
		public function set rMagDamage(val:String):void
		{
			//magInput.htmlStr = ProfileTools.retrieveDamage(_data,ProfileTools.MAGICAL);
		}
		
		/**
		 * 法防 
		 * @param val
		 * 
		 */
		public function set rMagDef(val:String):void
		{
			magDefInput.htmlStr=String(int((_data.GetPropertiesEx("MagDef")+_data.GetPropertiesEx("MagDefAdd"))*(1+_data.GetProperties("MagDefMul")/100) + 0.5));
		}
		
		/**
		 * 物防 
		 * @param val
		 * 
		 */
		public function set rPhyDef(val:String):void	
		{
			phyDefInput.htmlStr=String(int((_data.GetPropertiesEx("PhyDefAdd") + _data.GetPropertiesEx("PhyDef"))*(1 + _data.GetProperties("PhyDefMul")/100) + 0.5));
		}
		
		/**
		 * 气血HP
		 * @param val
		 * 
		 */
		public function set rHp(val:String):void
		{
//			HPInput.htmlStr=_data.GetPropertiesEx("HP")+"/"+(int(_data.GetPropertiesEx("MaxHP"))+int(_data.GetPropertiesEx("MaxHPAdd")));
			HPInput.htmlStr=_data.GetPropertiesEx("HP");
		}
		
		/**
		 * 添加Input数据 
		 * @param ipt 添加的input位置
		 * @param val 前面的数值
		 * @param valAdd 附加的数值
		 * 
		 */
		private function setVal(ipt:Input,val:int,valAdd:int):void
		{
			if(valAdd > 0)
			{
				ipt.showHtml = val.toString() + "+" + setColor(valAdd.toString());
			}
			else if(valAdd < 0)
			{
				ipt.showHtml = val.toString() + "-" + setColor(Math.abs(valAdd).toString(),"ff0000");
			}
			else
			{
				ipt.showHtml = val.toString();
			}
		}
		
		/**
		 * 设置文本颜色 
		 * @param str
		 * @param color
		 * @return 
		 * 
		 */
		private function setColor(str:String,color:String=ADDPROPCOLOR):String
		{
			return "<font color='#" + color +"'>" + str + "</font>";
		}
		//==========================清除方法=======================================
		/**
		 * 清除所有内容，为加载新的内容做准备 
		 * 
		 */
		public function clearAll():void
		{
			//清除内容
			HPInput.htmlStr = "";
			STInput.htmlStr = "";
			strInput.htmlStr = "";
			phyInput.htmlStr = "";
			ingInput.htmlStr = "";
			magInput.htmlStr = "";
			spiInput.htmlStr = "";
			phyDefInput.htmlStr = "";
			dexInput.htmlStr = "";
			magDefInput.htmlStr = "";
			_data = null;
			//接触绑定
			removeBindData();
		}
		
		/**
		 * 解绑数据 
		 * 
		 */
		private function removeBindData():void
		{
			//全部解绑
			for each(var itemBind:Array in _bindArr)
			{
				if(itemBind.length > 0)
				{
					bindManager.UnbindProp(itemBind.shift(),itemBind.shift(),itemBind.shift());
				}
			}
			_bindArr = [];
		}
	}
}